<template>
    <div class="content">
        <TableLayout form-title="">
        <div slot="form-title" class="table-title"></div>
            <el-form :model="formInline" ref="formInline" :rules="rules" class="formInline" label-width="100px" slot="form">          
                <el-row :gutter="41">
                    <el-col :span="8">
                        <el-form-item label="e学云ID号" prop="EId">
                            <el-input v-model="formInline.EId" placeholder="请输入e学云ID号" :maxlength="10"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="姓名">
                            <el-input v-model="formInline.userName" placeholder="请输入姓名" :maxlength="10"></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="手机号" prop="phone">
                            <el-input v-model="formInline.phone" placeholder="请输入手机号" :maxlength="11"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row :gutter="41">
                    <el-col :span="8">
                        <el-form-item label="身份">
                            <el-select v-model="formInline.userType" placeholder="请选择" style="width:100%">
                                <el-option v-for="item in formInline.userTypeList" :key="item.id" :label="item.name" :value="item.id">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="8">
                        <el-form-item label="账户状态">
                            <el-select v-model="formInline.interStatus" placeholder="请选择" style="width:100%">
                                <el-option v-for="item in formInline.interStatusList" :key="item.statusNum" :label="item.statusName" :value="item.statusNum">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row class="top-line">
                    <el-col :span="4" :offset="20"> 
                        <el-button type="primary" class="top-btn" @click="onSubmit('formInline')">查询</el-button>
                    </el-col>
                </el-row>
            </el-form>
            <div class="table-title" slot="table-title"></div>
            <el-table :data="dataApply" style="width: 100%" border  @selection-change="handleSelectionChange" v-loading="loading" ref="multipleTable">
                
                <el-table-column align="center" label="e学云ID号">
                    <template scope="scope">
                        <span>{{scope.row.exueCode || '--'}}</span>
                    </template>
                </el-table-column>
                
                <el-table-column align="center" label="姓名（用户名）">
                    <template scope="scope">
                        <span>{{scope.row.userName || '--'}}</span>
                    </template>
                </el-table-column>
                
                <el-table-column prop="userType " align="center" label="身份">
                    <template scope="scope">
                        <span v-if="scope.row.userType=='1'">教师</span>
                        <span v-if="scope.row.userType=='3'">家长</span>
                    </template>
                </el-table-column>

                <el-table-column prop="phone" align="center" label="手机号">
                    <template scope="scope">
                        <span>{{scope.row.phone || '--'}}</span>
                    </template>
                </el-table-column>

                <el-table-column prop="studentNum" align="center" label="余额账户（现金）">
                    <template scope="scope">
                        <el-button type="text" class="btn-success" @click="checkedYE(scope.row.id)">详情</el-button>
                    </template>
                </el-table-column>

                <el-table-column prop="studentNum" align="center" label="积分账户">
                    <template scope="scope">
                        <el-button type="text" class="btn-success" @click="checkedJF(scope.row.id)">详情</el-button>
                    </template>        
                </el-table-column>
                            
                <el-table-column label="状态" align="center" >
                    <template scope="scope">
                        <span v-if="scope.row.sStatus=='1'">冻结</span>
                        <span v-if="scope.row.sStatus=='0'">激活</span>
                    </template>
                </el-table-column>

                <el-table-column align="left" label="操作">
                    <template scope="scope">
                       <el-button type="text" class="btn-success" @click="sigleStart(scope.row.sStatus,scope.row.id)" v-if="scope.row.sStatus=='1'">激活</el-button>
                       <el-button type="text" class="btn-success" @click="sigleClose(scope.row.sStatus,scope.row.id)" v-if="scope.row.sStatus=='0'">冻结</el-button>
                    </template>
                </el-table-column>           
            </el-table>
            <div class="pagination-container" style="text-align:right">
                <el-pagination
                    layout="total, sizes, prev, pager, next, jumper"
                    :total="listQuery.total"
                    :current-page.sync="listQuery.page"
                    :page-sizes="config.pageSizes"
                    :page-size="config.pageSize"
                    @size-change="handleSizeChange"
                    @current-change="handleCurrentChange">
                </el-pagination>
            </div>
        </TableLayout>
    </div>
</template>

<script>
import TableLayout from 'components/TableLayout';
import {findEUserByPage, updateEStatus } from 'api/accountMagement';
import { mapState, mapActions, mapGetters } from 'vuex';
import province from 'components/CascadeRegion/province';
import city from 'components/CascadeRegion/city';
import region from 'components/CascadeRegion/region';
import validate from '@/utils/validate';
import school from 'components/SchoolClasss/school';
export default{
    components: {TableLayout, province, city, region, school},
    data() {
        return {
            formInline: {// form表单数据
                userName: '',
                phone: '',
                balanceStatus: '',
                interStatusList: [
                    {
                        statusNum: '',
                        statusName: '全部'
                    },
                    {
                        statusNum: '1',
                        statusName: '冻结'
                    },
                    {
                        statusNum: '0',
                        statusName: '激活'
                    }
                ],
                userTypeList: [
                    {
                        id: '1',
                        name: '教师'
                    },
                    {
                        id: '3',
                        name: '家长'
                    }
                ],
                userType: '1',
                EId: '',
                interStatus: ''
            },
            dataApply: [],
            listQuery: {// 分页
                page: 1,
                total: 0
            },
            loading: false,
            rules: {
                EId: [...validate.exueCode()],
                phone: [...validate.phone()]
            }
        }
    },
    computed: {
        ...mapState({
            config: state => state.config.table
        }),
        ...mapGetters([
            'uid'
        ])
    },
    
    methods: {
        // 全局获取行数
        ...mapActions(['ChangePageSize']),
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        // 分页
        handleSizeChange(val) {
            this.listQuery.page = 1;
            this.ChangePageSize(val);
            this.searchFetchData();
        },
        handleCurrentChange(val) {
            this.listQuery.page = val;
            this.searchFetchData();
        },
        // 查询列表
        searchFetchData() {
            if (this.formInline.userName=='' && this.formInline.EId=='' && this.formInline.phone=='') {
                this.$message({
                    type: 'info',
                    message: 'e学云ID号，姓名和手机号至少填写一项'
                });
                return '';
            }
            this.loading = true;
            findEUserByPage(this.listQuery.page, this.config.pageSize, this.formInline.interStatus, this.formInline.EId, this.formInline.userName, this.formInline.phone, this.formInline.userType).then(response => {              
                this.dataApply = response.data.content.list;
                this.listQuery.total = response.data.content.pagination.total;
                this.loading = false;    
            });
        },

        // 冻结账户
        sigleClose(row, id) {
            this.$confirm('确定要冻结账户吗?', ' ', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(() => {
                updateEStatus(row, id).then(res => {
                    this.searchFetchData();
                    this.$message({
                        type: 'success',
                        message: '冻结成功'
                    });
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },
        // 激活账户
        sigleStart(row, id) {
            this.$confirm('确定要激活账户吗?', ' ', {
                confirmButtonText: '确定',
                cancelButtonText: '取消'
            }).then(() => {
                updateEStatus(row, id).then(res => {
                    this.searchFetchData();
                    this.$message({
                        type: 'success',
                        message: '激活成功'
                    });
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });
        },

        // 表单查询
        // onSubmit() {
        //     this.listQuery.page = 1;
        //     this.searchFetchData();
        // },
        onSubmit(ruleForm) {
            this.$refs[ruleForm].validate((valid) => {
                if (valid) {
                    this.listQuery.page = 1;
                    this.searchFetchData();
                } else {
                    return false;
                }
            });
        },
        // 余额详情
        checkedYE(row) {
            this.$router.push({path: `checkFigure/${row}`});
        },

        checkedJF(row) {
            this.$router.push({path: `checkIntergral/${row}`});
        }
    }
}
</script>
<style lang="scss" scoped>
.content {
    position: relative;
    padding: 0px;
    $bgcolor:#fff;
    label{
        text-align:left;
    }
    .formInline {
        .formBtn{
            width: 100%;
            height: 70px;
            border-top: 1px solid #dddddd;
            position: relative;
            .btnPosition{
                position: absolute;
                right:0px; 
                top: 18px;
            }
        }
    }
}
</style> 